export const audioMixin = {
    methods: {
        mInit(duration) {
            this.stopFlag = false
            this.duration = parseInt(duration)
            this.audio.play()
        },
        mPlay() {
            this.animate = true
            this.timer = setInterval(() => {
                this.animate = false
                if (this.duration > 0) this.duration--
                setTimeout(() => {
                    this.animate = true
                }, 50)
            }, 1000)
        },
        mPause() {
            if (!this.stopFlag) {
                this.animate = false
                this.timer && clearInterval(this.timer)
            }
        },
        mStop() {
            this.stopFlag = true
            this.audio.pause()
            this.animate = false
            this.timer && clearInterval(this.timer)
            this.audio = null
            this.duration = 0
        },
        mEnd() {
            this.animate = false
            this.timer && clearInterval(this.timer)
            this.audio = null
            this.duration = 0
        }
    }
}
